<template>
  <el-dropdown placement="bottom-start">
    <span class="el-dropdown-link">
      <el-avatar icon="el-icon-user-solid"></el-avatar>
    </span>
    <el-dropdown-menu
      slot="dropdown"
      split-button="true"
    >
      <h2 style="text-align:center;color:lightblue">{{username1}}</h2>
      <el-dropdown-item style="text-align: left;">
        <el-button
          type="text"
          icon="el-icon-s-home"
          @click.native="personalcenter"
        >个人中心
        </el-button>
      </el-dropdown-item>

      <el-dropdown-item style="text-align: left;">
        <el-button
          type="text"
          icon="el-icon-question"
          @click.native="myquestion"
          :disabled="true"
        >我的提问
        </el-button>
      </el-dropdown-item>

      <el-dropdown-item style="text-align: left;">
        <el-button
          type="text"
          icon="el-icon-tickets"
          @click.native="mycontest"
          :disabled="true"
        >我的比赛
        </el-button>
      </el-dropdown-item>

      <el-dropdown-item style="text-align: left;">
        <el-button
          type="text"
          icon="el-icon-connection"
          @click.native="team"
          :disabled="true"
        >我的团队
        </el-button>
      </el-dropdown-item>

      <el-dropdown-item style="text-align: left;" v-if="flag===1">
        <el-button
          type="text"
          icon="el-icon-s-custom"
          @click.native="admin"
        >管理员界面
        </el-button>
      </el-dropdown-item>

      <el-dropdown-item
        divided
        style="text-align: center;"
      >
        <el-button
          type="text"
          icon="el-icon-switch-button"
          @click.native="logout"
        >注销
        </el-button>
      </el-dropdown-item>
    </el-dropdown-menu>
  </el-dropdown>
</template>

<script>
export default {
  name: 'UserLogin',
  mounted() {
      if(sessionStorage.getItem("username")==="caiyunqi" || sessionStorage.getItem("username")==="soledad")
        this.flag=1;
       console.log(this.flag)
    },
    data(){
      return{
         username1:sessionStorage.getItem("username"),
         flag:0
      }
    },
  methods: {
    myquestion(){
      this.$router.push('/user/myquestion', onComplete => { }, onAbort => { })
    },
    personalcenter(){
      this.$router.push('/user', onComplete => { }, onAbort => { })
    },
    mycontest(){
      this.$router.push('/user/mymatch', onComplete => { }, onAbort => { })
    },
    admin(){
      this.$router.push('/Adminpage', onComplete => { }, onAbort => { })
    },
    team(){
      this.$router.push('/team', onComplete => { }, onAbort => { })
    },
    logout () {
      this.$http.post('/api/user/logout').then(res=>{
          this.$message({
                message: "登出成功",
                type: "success",
                duration: 3000
              });
        // console.log(this.username1)
        sessionStorage.setItem("token","");
        setTimeout("window.location.reload()",1000);
      })
      
      // console.log(result)
      
    }
  }
}
</script>

<style lang = "less" scoped>
.userinfo {
  text-align: center;
  width: 100px;
}
</style>
